package com.stg.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.stg.bean.Department;
import com.stg.bean.Student;
import com.stg.dao.DepartmentDao;
import com.stg.service.DepartmentService;
import com.stg.service.StudentService;
@Service("departmentService")
public class DepartmentServiceImpl implements DepartmentService{

	@Resource
	private DepartmentDao departmentDao;
	
	@Resource
	private StudentService studentService;
	
	@Override
	public void createDepartment(Department department) {
		departmentDao.createDepartment(department);
	}

	@Override
	public void deleteDepartment(Long departmentId) {
		departmentDao.deleteDepartment(departmentId);
	}

	@Override
	public void updateDepartment(Department department) {
		departmentDao.updateDepartment(department);
	}

	@Override
	public List<Student> findAllStudentByDepartment(Long departmentId) {
		List<String> studentIdList = departmentDao.findAllStudentIdByDepartment(departmentId);
		List<Student> studentList = new ArrayList<Student>();
		for (String studentId : studentIdList) {
			Student student = studentService.findStudentById(studentId);
			studentList.add(student);
		}
		return studentList;
	}

	@Override
	public Department findDepartmentById(Long departmentId) {
		return departmentDao.findDepartmentById(departmentId);
	}

	@Override
	public List<Department> findAllDepartment(String assnName) {
		return departmentDao.findAllDepartment(assnName);
	}

}
